const http = require('../../util/http')
Page({
  onShareAppMessage() {
    return {
      title: '首页',
      path: 'entry/index/index',
    };
  },
  data: {
    baseurl: http.baseURL,
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    indicatorColor: 'white',
    indicatorActiveColor: 'red',
    vertical: false,
    autoplay: true,
    circular: true,
    current: 0,
    interval: 5000,
    duration: 1000,
    mode: 'widthFix',
    goodsList:['','','','',''],
    goodsDetail:null
  },
  onLoad(option){
    console.log('option--------',option)
    this.getActivityInfo(option.id)
  },
  getActivityInfo(id){
    xhs.showLoading({
      title: '加载中',
    })
    http.get('/api/merchantType/selectMerchantById/'+id,).then(res => {
      console.log('res',res)
      xhs.hideLoading()
			if (res.code == 200) {
        this.setData({
          goodsDetail:res.data
				})
			}
		})
  },
  openDetial(e) {
    console.log(e)
    const item = e.currentTarget.dataset.item
    xhs.navigateTo({
      url: '/entry/productDetail/index?id='+item.id
    });
  },
  creareOrder(e){
    const item = e.currentTarget.dataset.item
    let parms ={
      productId:item.id
    }
    http.get('/api/xhs/xhsBuyProduct',parms).then(res => {
      console.log('res',res)
			if (res.code == 200) {
        xhs.requestGuaranteeOrderPayment({
          orderInfo: {
            payToken: res.data.pay_token,
            orderId: res.data.order_id,
          },
          success: res => {
            xhs.hideLoading()
            xhs.showToast({
              title: '支付成功'
            })
            console.log('支付结果', res);
          },
          fail: res => {
            xhs.showToast({
              title: '支付失败',
              icon: 'none'
            });
            console.log('支付结果', res);
          },
        });
      } else if(res.code == 902){
        xhs.navigateTo({
          url: "/entry/login/index"
        });
      }
		})
  },
});
